<?php
namespace Core\Service;
use Phalcon\Session\Factory as SessionFactory;
use Phalcon\Di\Injectable;

class Session extends Injectable
{
    public function register() {
        $config = $this->config->session;
        if(!$config) {
            return null;
        }
        $this->di->setShared('session',
            function() use($config) {
                if(strtolower($config->adapter) == 'files') {
                    session_save_path($this->getDir()->var('session'));
                }
                $session = SessionFactory::load($config);
                $session->start();
                return $session;
            }
        );
        /*
        protected function _getSession() {
            //persistent = $this->di->getSessionBag([get_class(this)])
            return $this->getDI()->getSessionBag('oauth');
        }
        */
        return $this;
    }
}